<?php 

require("../include/config.php");
require("../API/php/fonctions.php");
require("../API/php/header.php");

// phpsql/mysql_getChargeByDate.php?milis=123456789&dateBegin=01011970&dateEnd=01012070&dateStatutBegin=01011970&dateStatutEnd=01012070

//[x][0] = date
//[x][1] = charge

// IN obligatoire
$arrayGet = array(
    "dateBegin" => null,
    "dateEnd" => null,
    "dateStatutBegin" => null,
    "dateStatutEnd" => null
);

$arrayValeur = recupGet($arrayGet, $bolDecode);

if($arrayValeur["error"] == null){
	// CONNECION SQL
	$db = mysql_connect($host, $base, $mdp)  or die('Erreur de connexion '.mysql_error());

	// CONNECION BASE
	mysql_select_db($base,$db)  or die('Erreur de selection '.mysql_error());

	$sql = "SELECT a.`date` , a.`charge` 
	FROM `affectation` a
	WHERE 1 =1
	AND a.`charge` <> 0
	AND a.`date` between LEAST(STR_TO_DATE('".$arrayValeur["dateBegin"]."','%d%m%Y'),STR_TO_DATE('".$arrayValeur["dateStatutBegin"]."','%d%m%Y')) AND GREATEST(STR_TO_DATE('".$arrayValeur["dateEnd"]."','%d%m%Y'),STR_TO_DATE('".$arrayValeur["dateStatutEnd"]."','%d%m%Y'))
	ORDER BY `date` ASC
	;";

	$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

	// on fait une boucle qui va faire un tour pour chaque enregistrement 
	while($data = mysql_fetch_assoc($req)) 
	{ 
		$strSorti .= $data['date'].'&'.$data['charge']
		.'&'
		." \r\n"; 
	}

	// DECONNECION SQL
	mysql_close();
}else{
	$strSorti = "ERROR:".$arrayValeur["error"];
}

require("../API/php/footer.php");
?>